package gui.commands.classDiagramCommands;

import data.DataVector;
import data.classDiagram.Entity;
import data.classDiagram.Member;
import gui.commands.ICommand;

/**
 * User: Szymon Kudzia
 * Date: 10.05.13
 * Time: 15:22
 */
public class DeleteMemberCommand implements ICommand {
	protected Entity entity;
	protected Member member;
	protected String name;

	public DeleteMemberCommand(Entity entity, String name) {
		this.entity = entity;
		this.name = name;
	}

	@Override
	public void execute() {
		for (Member m : entity.getMembers())
			if (m.getName().equals(name)) {
				member = m;
				break;
			}

		entity.removeMember(name);
		refresh();
	}

	@Override
	public void undo() {
		entity.addMember(member);
		refresh();
	}

	@Override
	public void redo() {
		entity.removeMember(name);
		refresh();
	}

	private void refresh() {
		DataVector.getInstance().refresh();
	}
}
